using System.Linq;

namespace TripleA.Core.Pipeline
{
    using System.Collections.Generic;
    using Interfaces;

    public class PipelineConfig<T> : IPipelineConfig<T>
    {
        private readonly List<IPipelineStep<T>> _steps;

        public PipelineConfig()
        {
            _steps = new List<IPipelineStep<T>>();
        }

        public PipelineConfig(IEnumerable<IPipelineStep<T>> steps)
            : this()
        {
            RunSteps(steps);
        }

        public IEnumerable<IPipelineStep<T>> Steps
        {
            get { return _steps; }
        }

        public IPipelineConfig<T> RunStep(IPipelineStep<T> step)
        {
            _steps.Add(step);
            return this;
        }

        public IPipelineConfig<T> RunSteps(IEnumerable<IPipelineStep<T>> steps)
        {
            if (steps == null || !steps.Any())
                return this;

            steps.ToList().ForEach(step => RunStep(step));
            return this;
        }
    }
}